package com.slg.android.listenbook.biz.bookcity.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.slg.android.listenbook.R;
import com.slg.android.listenbook.common.DataStore;
import com.slg.android.listenbook.moudle.RecommenList;
import com.slg.android.listenbook.moudle.RecommendBook;

import java.util.List;

/**
 * Created by Thinkpad on 2015/3/24.
 */
public class RecommendAdapter extends BaseAdapter {
    private Context context;
    //private RecommenList recommenList;
    private List<RecommendBook> data;

    public RecommendAdapter(Context context, RecommenList recommenList) {
        this.context = context;
        Log.d("RecommendAdapter",recommenList.toString());
        this.data = recommenList.getList();
        Log.d("data",data.toString());
    }

    @Override
    public int getCount() {
        Log.d("RecommendAdapter",data.size()+"");
        return data.size();

    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View ret = null;
        if (convertView != null) {
            ret = convertView;
        } else {
            ret = inflater.inflate(R.layout.item_recommend_gird, parent, false);
        }
        ViewHolder viewHolder = (ViewHolder) ret.getTag();
        if (viewHolder == null) {
            viewHolder = new ViewHolder();
            viewHolder.img = (ImageView) ret.findViewById(R.id.item_recommend_img);
            viewHolder.title = (TextView) ret.findViewById(R.id.item_recommend_title);
            viewHolder.islianzai = (TextView) ret.findViewById(R.id.item_recommend_islianzai);
            viewHolder.renqi = (TextView) ret.findViewById(R.id.item_recommend_renqi);
            ret.setTag(viewHolder);
        }

//        if (data != null) {
//            DataStore dataStore = DataStore.getInstance();
//            BitmapUtils utils = dataStore.getBitmapUtils();
//            utils.configDefaultLoadFailedImage(R.drawable.icon_fm_loading);
//            utils.configDefaultLoadingImage(R.drawable.icon_fm_loading);
//           // utils.display(viewHolder.img, data.get(position).getCover());
//
//            viewHolder.title.setText(data.get(position).getName());
//            viewHolder.renqi.setText("人气" + data.get(position).getHot());
//            if (data.get(position).getState().equals("2")) {
//                viewHolder.islianzai.setText("完结");
//                viewHolder.islianzai.setBackgroundColor(context.getResources().getColor(R.color.rec_over_bg));
//
//            } else {
//                viewHolder.islianzai.setText("连载");
//                viewHolder.islianzai.setBackgroundColor(context.getResources().getColor(R.color.text_red));
//            }
//
//        }
        return ret;
    }

    public class ViewHolder {
        private ImageView img;
        private TextView title;
        private TextView renqi;
        private TextView islianzai;

    }
}
